<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Creating New Record Types On-the-fly</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Record-types.xhtml" title="Record types"/>
    <link rel="next" href="Method-operations.xhtml" title="Calling Java methods from Scheme"/>
  </head>
  <body>
    <header/>
    <section class="sect1" title="Creating New Record Types On-the-fly" epub:type="subchapter" id="Dynamic-records">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both">Creating New Record Types On-the-fly</h2>
          </div>
        </div>
      </div>
      <p>Calling the <code class="literal">make-record-type</code> procedure creates a new record data
type at run-time, without any compile-time support.
It is primarily provided for compatibility; in most cases it is better
to use the <code class="literal">define-record-type</code> form (see <a class="link" href="Record-types.xhtml" title="Record types">Record types</a>).
</p>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871157952" class="indexterm"/> <code class="function">make-record-type</code> <em class="replaceable"><code>type-name</code></em> <em class="replaceable"><code>field-names</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a <em class="firstterm">record-type descriptor</em>, a value representing a new data
type disjoint from all others.  The <em class="replaceable"><code>type-name</code></em> argument must be a
string, but is only used for debugging purposes (such as the printed
representation of a record of the new type).  The <em class="replaceable"><code>field-names</code></em>
argument is a list of symbols naming the <em class="firstterm">fields</em> of a record of the
new type.  It is an error if the list contains any duplicates.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871147648" class="indexterm"/> <code class="function">record-constructor</code> <em class="replaceable"><code>rtd</code></em> [<em class="replaceable"><code>field-names</code></em>]</p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a procedure for constructing new members of the type represented
by <em class="replaceable"><code>rtd</code></em>.  The returned procedure accepts exactly as many arguments
as there are symbols in the given list, <em class="replaceable"><code>field-names</code></em>; these are
used, in order, as the initial values of those fields in a new record,
which is returned by the constructor procedure.  The values of any
fields not named in that list are unspecified.  The <em class="replaceable"><code>field-names</code></em>
argument defaults to the list of field names in the call to
<code class="literal">make-record-type</code> that created the type represented by <em class="replaceable"><code>rtd</code></em>;
if the <em class="replaceable"><code>field-names</code></em> argument is provided, it is an error if it
contains any duplicates or any symbols not in the default list.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871138992" class="indexterm"/> <code class="function">record-predicate</code> <em class="replaceable"><code>rtd</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a procedure for testing membership in the type represented by
<em class="replaceable"><code>rtd</code></em>.  The returned procedure accepts exactly one argument and
returns a true value if the argument is a member of the indicated record
type; it returns a false value otherwise.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871131568" class="indexterm"/> <code class="function">record-accessor</code> <em class="replaceable"><code>rtd</code></em> <em class="replaceable"><code>field-name</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a procedure for reading the value of a particular field of a
member of the type represented by <em class="replaceable"><code>rtd</code></em>.  The returned procedure
accepts exactly one argument which must be a record of the appropriate
type; it returns the current value of the field named by the symbol
<em class="replaceable"><code>field-name</code></em> in that record.  The symbol <em class="replaceable"><code>field-name</code></em> must be a
member of the list of field-names in the call to <code class="literal">make-record-type</code>
that created the type represented by <em class="replaceable"><code>rtd</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871125520" class="indexterm"/> <code class="function">record-modifier</code> <em class="replaceable"><code>rtd</code></em> <em class="replaceable"><code>field-name</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a procedure for writing the value of a particular field of a
member of the type represented by <em class="replaceable"><code>rtd</code></em>.  The returned procedure
accepts exactly two arguments: first, a record of the appropriate type,
and second, an arbitrary Scheme value; it modifies the field named by
the symbol <em class="replaceable"><code>field-name</code></em> in that record to contain the given value.
The returned value of the modifier procedure is unspecified.  The symbol
<em class="replaceable"><code>field-name</code></em> must be a member of the list of field-names in the call
to <code class="literal">make-record-type</code> that created the type represented by <em class="replaceable"><code>rtd</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871119216" class="indexterm"/> <code class="function">record?</code> <em class="replaceable"><code>obj</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a true value if <em class="replaceable"><code>obj</code></em> is a record of any type and a false
value otherwise.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871115408" class="indexterm"/> <code class="function">record-type-descriptor</code> <em class="replaceable"><code>record</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a record-type descriptor representing the type of the given
record.  That is, for example, if the returned descriptor were passed to
<code class="literal">record-predicate</code>, the resulting predicate would return a true
value when passed the given record.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871111392" class="indexterm"/> <code class="function">record-type-name</code> <em class="replaceable"><code>rtd</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the type-name associated with the type represented by rtd.  The
returned value is <code class="literal">eqv?</code> to the <em class="replaceable"><code>type-name</code></em> argument given in
the call to <code class="literal">make-record-type</code> that created the type represented by
<em class="replaceable"><code>rtd</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871106208" class="indexterm"/> <code class="function">record-type-field-names</code> <em class="replaceable"><code>rtd</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns a list of the symbols naming the fields in members of the type
represented by <em class="replaceable"><code>rtd</code></em>.  The returned value is <code class="literal">equal?</code> to the
field-names argument given in the call to <code class="literal">make-record-type</code> that
created the type represented by <em class="replaceable"><code>rtd</code></em>.
</p>
        </blockquote>
      </div>
      <p>Records are extensions of the class <code class="literal">Record</code>.
These procedures use the Java 1.1 reflection facility.
</p>
    </section>
    <footer>
      <div class="navfooter">
        <p>
          Up: <a accesskey="u" href="Objects-Classes-and-Modules.xhtml">Object, Classes and Modules</a></p>
        <p>
        Previous: <a accesskey="p" href="Record-types.xhtml">Record types</a></p>
        <p>
        Next: <a accesskey="n" href="Method-operations.xhtml">Calling Java methods from Scheme</a></p>
      </div>
    </footer>
  </body>
</html>
